package com.recruit.server.controller;

import com.recruit.server.common.AccessAble;
import com.recruit.server.common.HeaderInfo;
import com.recruit.server.request.user.LogOutRequest;
import com.recruit.server.request.user.LoginRequest;
import com.recruit.server.request.user.RegisterRequest;
import com.recruit.server.response.user.LogOutResponse;
import com.recruit.server.response.user.LoginResponse;
import com.recruit.server.response.user.RegisterResponse;
import com.recruit.server.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService iUserService;

    /**
     * login api
     */
    @AccessAble // @AccessAble注解的方法不需要进行用户信息校验
    @PostMapping("/login")
    public LoginResponse login(@Validated @RequestBody LoginRequest request, HttpSession httpSession) {
        return iUserService.login(request, httpSession);
    }

    /**
     * register api
     */
    @PostMapping("/register")
    public RegisterResponse register(@Validated @RequestBody RegisterRequest request, HeaderInfo headerInfo) {
        return iUserService.register(request, headerInfo);
    }

    /**
     * logOut api
     */
    @PostMapping("/logOut")
    public LogOutResponse logOut(HttpServletRequest servletRequest, HttpSession httpSession) {
        return iUserService.logOut(servletRequest, httpSession);
    }
}
